﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RRSimulator.BlobManager.Lib.Model
{
    public delegate void BlockCompletedEventHandler(object sender, string blockId);

    public class BlockModel : ModelBase
    {
        private bool _isDisposed;
        private bool _isCompleted;

        public event BlockCompletedEventHandler BlockCompleted; 

        public string BlockId { get; set; }
        public int StartIndex { get; set; }
        public int BlockSize { get; set; }
        public bool IsCompleted
        {
            get { return _isCompleted; }
            set
            {
                _isCompleted = value;

                if (_isCompleted && BlockCompleted != null)
                {
                    BlockCompleted(this, BlockId);
                }
            }
        }
        public bool IsFailed { get; set; }
        public int CurrentRetryTimes { get; set; }

        ~BlockModel()
        {
            Dispose(false);
        }

        protected override void Dispose(bool isDisposing)
        {
            if (_isDisposed)
                return;

            if (isDisposing)
            {

            }

            base.Dispose(isDisposing);
        }
    }
}
